package com.hospital.drug.drugyan.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hospital.drug.drugyan.entity.Doctor_falls;
import com.hospital.drug.drugyan.entity.Doctor_information;
import com.hospital.drug.drugyan.entity.Resignation_Form;
import com.hospital.drug.drugyan.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @description：
 * @author：zou
 * @date：2021/9/22 19:51
 * @versions：v1.0
 */
@Controller
@RequestMapping("/doctorY")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    //分页查询
    @RequestMapping("/doctorPage")
    public ModelAndView doctorPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "") String name) {
        ModelAndView mv = new ModelAndView();
        PageInfo<Doctor_information> page = doctorService.pageListDoctor(pageNum, name);
        mv.addObject("page", page);
        mv.addObject("name", name);
        mv.setViewName("drug/drugyan/doctorSelect");
        return mv;
    }

    @RequestMapping("/addDoctor")
    @ResponseBody
    public String addDoctor(String doctorMsg) {
        String[] msg = doctorMsg.split(",");
        Doctor_information doctor = new Doctor_information(msg[0], msg[1], Integer.parseInt(msg[2]), msg[3], msg[4], msg[5], msg[6], msg[7], msg[8], msg[9]);
        boolean b = doctorService.insertDoctor(doctor);
        return JSON.toJSONString(b);
    }

    @RequestMapping("/delDoctor")
    @ResponseBody
    public String delDoctor(Integer id) {
        boolean b = doctorService.deleteDoctor(id);
        return JSON.toJSONString(b);
    }

    @RequestMapping("/updDoctor")
    @ResponseBody
    public String updDoctor(Integer id, String doctorMsg) {
        String[] msg = doctorMsg.split(",");
        Doctor_information doctor = new Doctor_information(id, msg[0], msg[1], Integer.parseInt(msg[2]), msg[3], msg[4], msg[5], msg[6], msg[7], msg[8], msg[9]);
        boolean b = doctorService.updateDoctor(doctor);
        return JSON.toJSONString(b);
    }

    @RequestMapping("/insertDuty")
    @ResponseBody
    public String insertDuty(String doctorId,String dept,String date,String type){
        boolean b = doctorService.insertDuty(new Doctor_falls(dept, Integer.parseInt(doctorId), date, Integer.parseInt(type)));
        return JSON.toJSONString(b);
    }

    @RequestMapping("/lizhi")
    @ResponseBody
    public String selectRes(){
        List<Resignation_Form> resignation_form = doctorService.selectRes();
        return JSON.toJSONString(resignation_form);
    }
}
